#include "escape.h"

#include <map>
#include <string>


namespace html
{

static const std::map<char, std::string> g_charToEscape{
    {'<',"&lt;"},
    {'>',"&gt;"},
    {'"',"&quot;"},
    {'\'',"&apos;"},
    {'&',"&amp;"},
};

void Escape::escape(std::ostream &out) const {
    for (char c : str_) {
        const auto it = g_charToEscape.find(c);
        if (it == g_charToEscape.end()) {
            out << c;
        } else {
            out << (it->second);
        }
    }
}

} // namespace html
